<template>
    <view class="content">

        <view class="edit" v-if="item.cirStatus!=1">

            <view class=""
                v-if="(item.approvalStatus!=1&&getS('role')=='业务员')||getS('role')=='业务主管'||getS('role')=='董事长'||uid==item.customerUser.userId"
                @click.stop="editFn(`/pages/customer/add?isEdit=1`)"><button style="height: 28px; font-size: 12px;background-color: chocolate;">修改</button></view>
				<br>
				&nbsp;
			<view class=""
			    v-if="(item.customerUser<7&&getS('role')=='业务员')||getS('role')=='业务主管'||getS('role')=='董事长'||uid==item.customerUser.userId"
			    @click.stop="remove"><button style="height: 28px; font-size: 12px;background-color: brown;">删除</button></view>	

            <view style="padding-left: 16rpx;"
                v-if="((item.approvalStatus==2||item.approvalStatus==3)&&uid==item.customerUser.userId)"
                @click.stop="examineFn">
                提交审核
            </view>
        </view>


        <view class="info-box">
            <!-- <view class="head">基本信息</view> -->
            <view class="item column">
                <text class="label">客户编号</text>
                <text class="text">{{item.customerCode}}</text>
            </view>
            <view class="item column">
                <text class="label">客户名称</text>
                <text class="text">{{item.customerName}}</text>
            </view>

            <view class="item column">
                <text class="label">手机</text>
                <text class="text blue" @click="callPhone(item.mobile)">{{item.mobile}}</text>
            </view>
            <view class="item column">
                <text class="label">身份证号</text>
                <text class="text blue">{{item.cardId}}</text>
            </view>
            <view class="item column">
                <text class="label">业务类型</text>
                <text class="text blue">{{['','个人','企业'][item.customerType]}}</text>
            </view>
            <view class="item column" v-if="item.comeFrom">
                <text class="label">获客途径</text>
                <text class="text blue">{{utils.getDictLabelName("comeFromList",item.comeFrom)}}</text>
            </view>
            <view class="item column" v-if="item.companyName&&item.customerType==2">
                <text class="label">公司名称</text>
                <text class="text blue">{{item.companyName}}</text>
            </view>
            <view class="item column" v-if="item.customerUser">
                <text class="label">金融顾问</text>
                <text class="text blue">{{item.customerUser.userNickName||'未分配'}}</text>
            </view>

            <view class="item column" v-if="item.guarantorName">
                <text class="label">担保人</text>
                <text class="text blue">{{item.guarantorName}}</text>
            </view>

            <view class="item column" v-if="item.guarantorPhone">
                <text class="label">担保人手机</text>
                <text class="text blue">{{item.guarantorPhone}}</text>
            </view>
            <view class="item column" v-if="item.guarantorCardId">
                <text class="label">担保人身份证号</text>
                <text class="text blue">{{item.guarantorCardId}}</text>
            </view>
            <view class="item column" v-if="item.guarantorAddress">
                <text class="label">担保人地址</text>
                <text class="text blue">{{item.guarantorAddress}}</text>
            </view>

            <view class="item column">
                <text class="label">业务名称</text>
                <text class="text blue"> {{['','垫资','信贷','商户贷','税票贷','抵押贷','房产抵押','个人经营贷'][item.handingMethod]}}</text>
            </view>
            <view class="item column" v-if="item.bankName">
                <text class="label">银行名称</text>
                <text class="text blue">{{item.bankName}}</text>
            </view>
            <view class="item column">
                <text class="label">需求金额</text>
                <text class="text blue">{{item.estimatedAmount}}</text>
            </view>

            <view class="item column" v-if="item.feeStatus==0&&item.deposit">
                <text class="label">定金</text>
                <text class="text blue">{{item.deposit}}</text>
            </view>

            <view class="item column" v-if="item.feeStatus==0&&item.serCharge">
                <text class="label">服务费</text>
                <text class="text blue">{{item.serCharge}}</text>
            </view>

            <view class="item column">
                <text class="label">创建时间</text>
                <text class="text">{{item.createTime}}</text>
            </view>
            <view v-if="[8].includes(item.customerUser.status-0)&&imp.bankName">
                <view class="item column">
                    <text class="label" style="font-weight: 800;color: #000;">放款信息</text>
                </view>

                <view class="item column">
                    <text class="label">银行名称</text>
                    <text class="text">{{imp.bankName}}</text>
                </view>
                <view class="item column">
                    <text class="label">放款金额</text>
                    <text class="text">{{imp.amount}}</text>
                </view>
                <view class="item column">
                    <text class="label">放款日期</text>
                    <text class="text">{{imp.releaseDate}}</text>
                </view>
                <view class="item column">
                    <text class="label">还款方式</text>
                    <text class="text">{{imp.repayMethod-0===0?'先息后本':'等额本息'}}</text>
                </view>
                <view class="item column">
                    <text class="label">总还款本金</text>
                    <text class="text">{{imp.repayAmount}}</text>
                </view>
                <view class="item column">
                    <text class="label">还款利率</text>
                    <text class="text">{{imp.rate}}%</text>
                </view>
                <view class="item column">
                    <text class="label">每月还款日</text>
                    <text class="text">{{imp.releaseDay}}</text>
                </view>
                <view class="item column">
                    <text class="label">每月还款金额</text>
                    <text class="text">{{imp.repayMonth}}</text>
                </view>
                <view class="item column">
                    <text class="label">初次还款日</text>
                    <text class="text">{{imp.releaseBeginDate}}</text>
                </view>
                <view class="item column">
                    <text class="label">末次还款日</text>
                    <text class="text">{{imp.releaseEndDate}}</text>
                </view>
                <view class="item column">
                    <text class="label">授信期限</text>
                    <text class="text">{{imp.creditTerm}}月</text>
                </view>

            </view>



            <view class="item column">
                <text class="label">最后更新时间</text>
                <text class="text">{{item.receiveTime}}</text>
            </view>
        </view>


        <view class="footBox" v-if="item.cirStatus!=1">
            <!-- 
             role=='' 
             业务 item.customerUser.userId
             贷后客服 item.customerUser.postpersonId 
             执行 item.customerUser.executorId
             -->
            <view class="seat"></view>
            <!-- 1待邀约 2邀约失败 -->
            <view class="foot" v-if="uid==item.customerUser.userId&&[1,2].includes(item.customerUser.status-0)">
                <view class="btn" v-if="[1,2].includes(item.customerUser.status-0)"
                    @click="to(`/pages/customer/examine2?type=邀约成功`)">邀约成功</view>
                <view class="btn" v-if="[1].includes(item.customerUser.status-0)"
                    @click="to(`/pages/customer/examine2?type=邀约失败`)">
                    邀约失败</view>
            </view>
            <!-- 3上传 4拒传 -->
            <view class="foot" v-if="uid==item.customerUser.postpersonId&&[3,4].includes(item.customerUser.status-0)">
                <view class="btn" v-if="[3,4].includes(item.customerUser.status-0)"
                    @click="to(`/pages/customer/addinvfile?type=上传征信`)">上传征信</view>
                <view class="btn" v-if="[3].includes(item.customerUser.status-0)"
                    @click="to(`/pages/customer/examine2?type=拒传征信`)">
                    拒传征信</view>
            </view>
            <!-- 5上传 6拒签 -->
            <view class="foot" v-if="uid==item.customerUser.postpersonId&&[5,6].includes(item.customerUser.status-0)">
                <view class="btn" v-if="[5,6].includes(item.customerUser.status-0)"
                    @click="to(`/pages/customer/addcusfile?type=上传合同`)">上传合同</view>
                <view class="btn" v-if="[5].includes(item.customerUser.status-0)"
                    @click="to(`/pages/customer/examine2?type=拒签合同`)">
                    拒签合同</view>
            </view>
            <!-- 7待执行 8放款成功 9放款失败 -->
            <view class="foot" v-if="uid==item.customerUser.userId&&[7,8,9].includes(item.customerUser.status-0)
            &&item.handingMethod!=1">
                <view class=" btn" v-if="[7,9].includes(item.customerUser.status-0)" @click="impFn">
                    执行成功</view>


                <view class="btn" v-if="[7].includes(item.customerUser.status-0)"
                    @click="to(`/pages/customer/examine2?type=执行失败`)">
                    执行失败</view>
            </view>
			<!-- 回款 -->
            <view class="foot" v-if="(uid==item.customerUser.userId||getS('role')=='董事长')&&[7,8,9].includes(item.customerUser.status-0)
            &&item.handingMethod==1&&item.customerUser.cirStatus==0">
                <view class=" btn" v-if="[7,8,9].includes(item.customerUser.status-0)" @click="rollBackFn">
                    回款完毕</view>
            </view>

            <view class="foot" v-if="[8].includes(item.customerUser.status-0) && !item.imp.bankName && (uid==item.customerUser.executorId||uid==item.customerUser.userId)&&item.handingMethod!=1            
            ">
                <view class=" btn" @click="to(`/pages/customer/imp`)">
                    上传执行信息</view>

            </view>
			<!-- 写跟进 -->
			<!-- <view class="foot" style="padding-top: 10px;">
			    <view class="btn" @click="addFollow">写跟进</view>
			</view> -->
        </view>

        <!-- 未促成 并且有定金 并且未退回 并且是贷后
        定金deposit 服务费 serCharge 状态feeStatus0 未退回 1 已退回 -->
        <view class="footBox"
            v-if="item.customerUser && item.cirStatus==1&&uid==item.customerUser.postpersonId&&item.deposit&&item.feeStatus==0">
            <view class="foot">
                <view class="btn fc" @click="backDj">退定金</view>
            </view>
        </view>


    </view>
</template>

<script>
    import api from '@/api/api.js';
    export default {
        data() {
            return {
                imp: {},
                item: {},
                role: '',
                uid: '',
            }
        },
        mounted() {
            this.role = this.getS('role')
            this.uid = JSON.parse(this.getS('user')).userId
        },
        onLoad() {
            // 修改顶部导航背景色
            uni.setNavigationBarColor({
                frontColor: '#ffffff',
                backgroundColor: '#39b54a',
                animation: {
                    duration: 400,
                    timingFunc: 'easeIn'
                }
            })
        },
        methods: {

            backDj() {
                api.feeCover({
                    customerId: this.item.customerId,
                }).then(r => {
                    this.toast(`操作成功`)
                    this.item.feeStatus = 1
                    this.$forceUpdate()
                })
            },
            impFn() { //执行成功
                uni.showModal({
                    content: `确定执行成功了吗？`,
                    success: (r) => {
                        if (r.confirm) {
                            api.impEdit({
                                customerId: this.item.customerId + '',
                                impStatus: '1',
                                impId: this.item.impId + '',
                            }).then(
                                res => {
                                    if (res.code == 200) {
                                        uni.showToast({
                                            title: '提交成功',
                                            duration: 2000
                                        });
                                        this.item.customerUser.status = 8

                                    } else {
                                        uni.showToast({
                                            title: res.msg,
                                            icon: 'none',
                                        });
                                    }

                                },
                                rej => {}
                            );
                        }
                    }
                })

            },
			// 写跟进
			addFollow() {
				console.log(this.item);
			    uni.navigateTo({
			        url: './addFollow/index?customerId=' + this.item.customerId + "&customerUserId=" + this.item
			            .customerUserId
			    })
			},
			rollBackFn() { //回款成功
			    uni.showModal({
			        content: `确定回款成功了吗？`,
			        success: (r) => {
			            if (r.confirm) {
			                api.rollBackAmount({
			                    customerId: this.item.customerId + '',
			                }).then(
			                    res => {
			                        if (res.code == 200) {
			                            uni.showToast({
			                                title: '提交成功',
			                                duration: 2000
			                            });
			                            this.item.customerUser.cirStatus = 2;
										// uni.reload();
										wx.redirectTo({
										  url: '/pages/customDetail?customerId=' + item.customerId
										})
			                        } else {
			                            uni.showToast({
			                                title: res.msg,
			                                icon: 'none',
			                            });
			                        }
			
			                    },
			                    rej => {}
			                );
			            }
			        }
			    })
			
			},
            examineFn() {
                //提交审核
                api.approval({
                    customerId: this.item.customerId,
                    approvalStatus: 0,
                }).then(res => {
                    if (res.code == 200) {
                        uni.showToast({
                            title: '操作成功',
                            duration: 2000
                        });
                        this.item.approvalStatus = 0
                    } else {
                        uni.showToast({
                            title: res.msg,
                            icon: 'none',
                        });
                    }
                })
            },
			remove() {
				console.log(this.item.customerId);
				var data = {customerId : this.item.customerId}; 
				uni.showModal({
				    title: '提示',
				    content: '确定删除' + this.item.customerName + '吗',
				    success: function(res) {

				        api.removeCustomer(data).then(res => {
				            if (res.code == 200) {
				                // uni.showToast({
				                //     title: '操作成功',
				                //     duration: 2000
				                // });
								// uni.redirectTo({
								//     url: '../pages/customer/index',
								// });
								uni.showToast({
								    title: '提交成功',
								    duration: 2000
								});
								setTimeout(function() {
								     uni.reLaunch({
								       url: '/pages/customer/index'
								    })
								}, 500);
				        		// to(`/pages/customer/index`);
				                // this.item.approvalStatus = 0
				            } else {
				                uni.showToast({
				                    title: res.msg,
				                    icon: 'none',
				                });
				            }
				        })
				    }
				});
			},
            editFn(url) {
                console.log(`edit`, this);
                uni.setStorageSync('editObj', this.item)
                uni.navigateTo({
                    url
                })
            },
            getCustomerDetails(data) {
                this.item = data;
                if (data.imp) this.imp = data.imp
            },
            // 拨打电话
            callPhone(tel) {
                uni.makePhoneCall({
                    phoneNumber: tel
                })
            },
            goLocation() {
                uni.openLocation({
                    latitude: parseFloat(this.item.lat),
                    longitude: parseFloat(this.item.lng),
                    scale: 18
                })
            }
        }
    }
</script>

<style scoped lang="scss">
    .footBox {
        .seat {
            height: 100rpx;
        }

        .foot {
            height: 100rpx;
            width: 750rpx;
            position: fixed;
            left: 0;
            bottom: 0;
            background-color: #fff;
            display: flex;
            align-items: center;
            justify-content: center;
            padding: 16rpx;
            flex: 1;

            .btn {
                min-width: 300rpx;
                margin: 0 16rpx;
                height: 68rpx;
                border-radius: 60rpx;
                background-color: #2EB76F;
                display: flex;
                flex: 1;
                align-items: center;
                justify-content: center;
                color: #fff;
            }
        }
    }

    .content {
        background: #fff;
        padding-bottom: 20upx;
        position: relative;

        .edit {
            display: flex;
            position: absolute;
            right: 30rpx;
            top: 30rpx;
            color: #0aAC44;
        }

        .info-box {
            .head {
                height: 60upx;
                line-height: 60upx;
                font-size: 32upx;
                color: #000;
                font-weight: bold;
                position: relative;
                padding: 10upx 50upx;
                // &::after{
                // 	content: "";
                // 	width: 10upx;
                // 	height: 10upx;
                // 	border-radius: 5upx;
                // 	background: #333;
                // 	position: absolute;
                // 	top: 50%;
                // 	transform: translateY(-50%);
                // 	left: 20upx;
                // }
            }

            .item {
                height: 90upx;
                line-height: 90upx;
                padding: 0 50upx;
                border-bottom: 1px solid #f7f7f7;

                &:last-child {
                    border-bottom: none;
                }

                &.column {
                    height: auto;
                    display: flex;
                    flex-direction: column;

                    .text {
                        margin-bottom: 20upx;
                        line-height: 1.5;
                    }
                }

                .label {
                    font-size: 30upx;
                    color: #999;
                    margin-right: 30upx;
                }

                .text {
                    font-size: 32upx;
                    color: #000;

                    &.blue {
                        color: #2172FF;
                    }
                }
            }
        }
    }
</style>